import { authenticateRequest } from '@/utils/auth';
import { NextRequest } from 'next/server';
import { withMiddleware } from '@/lib/middleware/entry';
import { successResponse, errorResponse } from '@/lib/response';
import { prisma } from '@/lib/prisma';
import { Agent } from '@prisma/client';

async function handler(req: NextRequest) {
  const authResult = await authenticateRequest(req);
  if (!authResult.success) {
    return errorResponse(authResult.error || '身份验证失败');
  }

  const data = (await req.json()) as Omit<Agent, 'id' | 'createdAt' | 'updatedAt'>;

  const createdAgent = await prisma.agent.create({ data });

  return successResponse(createdAgent, '创建成功');
}

export const POST = withMiddleware(handler);